const {
	Service
} = require('dx-router-admin')
const {
	DxResource
} = require('dx-func-entity')

module.exports = class Resource extends Service {
	constructor(ctx) {
		super(ctx);
		this.entity = DxResource;		
	}
	//初始化
	init() {
		this.$on('before_insert',function(data){
			data.user_id = this.$dx.auth.uid;
		});
		// //删除，去删除云文件
		// this.$on('after_delete',function(that) {
		// 	await uniCloud.deleteFile({
		// 		fileList: [that.fileID]
		// 	});
		// })
	}
	async todayResource() {
		// 获取今日新增资源
		let now = new Date();
		let startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		let timestamp = startOfDay.getTime();
		const dbCmd = this.$dx.db.command;
		const todayTotal = await this.where(
			{
				create_date: dbCmd.gte(timestamp),
			},
			true
		).count();
		return todayTotal;
	}
}
